package cn.oowoo.rabbitmq.config;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

public class RabbitConfig {
    //RabbitMQ链接参数
    public static final String HOST = "oowoo.cn";
    public static final int PORT = 5672;
    public static final String USER_NAME = "test001";
    public static final String PASSWORD = "123";
    public static final String VIRTUAL_HOST = "/";


    //测试ACk确认用队列
    public final static String QUEUE_ACK_NAME = "TEST_ACK_QUEUE";

    //测试简单消 送交换机、队列和路由键
    public final static String EXCHANGE_SIMPLE_NAME = "SIMPLE_EXCHANGE";
    public final static String QUEUE_SIMPLE_NAME = "SIMPLE_QUEUE";
    public final static String ROUTING_SIMPLE_KEY = "simple.test.key";

    //测试优先级消息 交换机、队列和路由键
    public final static String EXCHANGE_PRIORITY_NAME = "PRIORITY_EXCHANGE";
    public final static String QUEUE_PRIORITY_NAME = "PRIORITY_QUEUE";//优先级队列
    public final static String QUEUE_NORMAL_NAME = "NORMAL_QUEUE";//普通队列（用于跟优先级队列对比）
    public final static String ROUTING_PRIORITY_KEY = "priority.test.key";

    //测试TTL消息
    public final static String QUEUE_TTL_NAME = "QUEUE_TTL_NAME";

    //测试限流测试交换机、队列和路由键
    public final static String EXCHANGE_LIMIT_NAME = "LIMIT_EXCHANGE";
    public final static String QUEUE_LIMIT_NAME = "LIMIT_QUEUE";
    public final static String QUEUE_NO_LIMIT_NAME = "NO_LIMIT_QUEUE";
    public final static String ROUTING_PLIMIT_KEY = "limit.test.key";

    //测试消息不可达消息交换机、队列和路由键
    public final static String EXCHANGE_RETURNLISTENER_NAME = "RETURNLISTENER_EXCHANGE";
    public final static String QUEUE_RETURNLISTENER_NAME = "RETURNLISTENER_QUEUE";
    public final static String ROUTING_RETURNLISTENER_KEY = "returnListener.test.key";//可匹配到的routingkey
    public final static String ROUTING_RETURNLISTENER_KEY_1 = "xxx.test.key";//模拟匹配不到的routingkey

    //测试confirm模式用队列
    public final static String QUEUE_CONFIRM_NAME = "QUEUE_CONFIRM_NAME";

    //测试transaction模式用队列
    public final static String QUEUE_TRANSACTION_NAME = "QUEUE_TRANSACTION_NAME";

    //测试DLX用交换机、队列和路由键
    public final static String EXCHANGE_DLX_NONE_NAME = "EXCHANGE_DLX_NONE_NAME";//交换机
    public final static String QUEUE_DLX_NONE_NAME = "QUEUE_DLX_NONE_NAME";//队列
    public final static String ROUTING_DLX_NONE_KEY = "dlx.test.key";//匹配到的routingkey
    public final static String EXCHANGE_DLX_NAME = "EXCHANGE_DLX_NAME";//死信交换机
    public final static String QUEUE_DLX_NAME = "QUEUE_DLX_NAME";//死信队列
    public final static String ROUTING_DLX_KEY = "dlx.*.key";//匹配到的死信routingkey

    //测试延迟队列用交换机、队列和路由键
    public final static String EXCHANGE_DEALY_NAME = "EXCHANGE_DEALY_NAME";//交换机
    public final static String QUEUE_DELAY_NAME = "QUEUE_DELAY_NAME";//队列
    public final static String ROUTING_DELAY_KEY = "delay.test.key";//匹配到的routingkey

    //测试RPC远程调用交换机、队列和路由键
    public final static String EXCHANGE_RPC_NAME= "EXCHANGE_RPC_NAME";
    public final static String QUEUE_RPC_REQUEST_NAME = "QUEUE_RPC_REQUEST_NAME";//队列
    public final static String ROUTING_RPC_KEY = "ROUTING_RPC_KEY";//路由key
    public final static String QUEUE_RPC_RESPONSE_NAME = "QUEUE_RPC_RESPONSE_NAME";//回调队列



    public static Connection createConnection() throws IOException, TimeoutException {
        ConnectionFactory factory = new ConnectionFactory();
        // 连接IP
        factory.setHost(RabbitConfig.HOST);
        // 默认监听端口
        factory.setPort(RabbitConfig.PORT);
        // 虚拟机
        factory.setVirtualHost(RabbitConfig.VIRTUAL_HOST);
        // 设置访问的用户
        factory.setUsername(RabbitConfig.USER_NAME);
        factory.setPassword(RabbitConfig.PASSWORD);

        // 建立连接
        Connection connection = factory.newConnection();
        return connection;
    }
}
